﻿using HardcoreGame.Common.Systems;
using HardcoreGame.Content.Buffs;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;

namespace HardcoreGame.Common.Players
{
    public class EventPlayer : ModPlayer
    {      
        public bool acidRain; // 酸雨
        public override void ResetEffects()
        {
            acidRain = false;
        }
        public override void PreUpdate()
        {
            Player.ManageSpecialBiomeVisuals("AcidRain", acidRain, Player.Center);
            if (EventSystem.activeEvents.Contains(1) && Player.ZoneOverworldHeight)
            {
                int num18 = (int)Player.Center.X / 16;
                int num19 = (int)Player.Center.Y / 16;
                if (Main.tile[num18, num19 + 1].TileType == 0 || Main.tile[num18, num19].WallType == 0)
                {
                    Player.AddBuff(ModContent.BuffType<Corrosion>(), 600, true);
                }
            }
            for (int i = 0; i < 100; i++)
            {
                NPC npc = Main.npc[i];
                int num18 = (int)npc.Center.X / 16;
                int num19 = (int)npc.Center.Y / 16;
                if (Main.tile[num18, num19 + 1].TileType == 0 || Main.tile[num18, num19].WallType == 0)
                {
                    if (npc.life >= 1 && EventSystem.activeEvents.Contains(1) && Player.ZoneOverworldHeight)
                    {
                        npc.AddBuff(ModContent.BuffType<Corrosion>(), 10, false);
                    }
                }
            }          
        }        

        public override void CatchFish(FishingAttempt attempt, ref int itemDrop, ref int npcSpawn, ref AdvancedPopupRequest sonar, ref Vector2 sonarPosition)
        {
            if (EventSystem.activeEvents.Contains(2))
            {
                Main.NewText(Language.GetTextValue("Mods.HardcoreGame.Tips.3"), Color.Red);
                itemDrop = ItemID.None;
                if (Main.rand.NextBool(10))
                {
                    NPC.SpawnOnPlayer(Player.whoAmI, NPCID.DukeFishron);
                }
            }
        }
    }
}
